home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1996 June / Software of the Month Club 1996 June.iso / pc / dos / dtp / display / drvsrc / s3805_1m.asm < prev    next >
Assembly Source File  |  1994-12-20  |  16KB  |  553 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file VESA_S3.ASM
  3. ;
  4. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. ; Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6. ; Copyright (C) 1992 Shayne Hughes, UC Davis, CA 95616
  7. ;
  8. ; This file is distributed under the terms listed in the document
  9. ; "copying.dj", available from DJ Delorie at the address above.
  10. ; A copy of "copying.dj" should accompany this file; if not, a copy
  11. ; should be available from where this file was obtained.  This file
  12. ; may not be distributed without a verbatim copy of "copying.dj".
  13. ;
  14. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  15. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. ;--------------------------------------------------------------------------
  17.  
  18. ; NOTE: this file was formerly called STEALTH.ASM
  19. ; It seems that for once the industry is succeeding in manufacturing
  20. ; compatible graphics boards, as this driver, orginally written for a
  21. ; Diamond Stealth board seems to work unchanged on Orchid F1280 and
  22. ; similar S3 based boards, AND EVEN local bus S3 boards.
  23. ; Thanks to Shayne Hughes, we now have a paging routine for this
  24. ; driver. This allows direct memory access to the video RAM - although
  25. ; GRX is not using it.
  26.  
  27. _TEXT    segment byte public 'CODE'
  28. _TEXT    ends
  29. DGROUP  group    _TEXT,_DATA,_BSS
  30.     assume  cs:_TEXT,ds:DGROUP
  31. _DATA    segment word public 'DATA'
  32. d@    label    byte
  33. d@w    label    word
  34. _DATA    ends
  35. _BSS    segment word public 'BSS'
  36. b@    label    byte
  37. b@w    label    word
  38. _BSS    ends
  39. _TEXT    segment byte public 'CODE'
  40.     assume  cs:_TEXT,ds:DGROUP
  41.  
  42. include grdriver.inc
  43.  
  44. ;--------------------------------------------------------------------------
  45. ; DRIVER HEADER
  46. ;  The following entries MUST match the structure and constant
  47. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  48. ;  The mode word should contain the following bitfields:
  49. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  50. ;     - the adapter type field should be specified
  51. ;     - the memory size field should be specified
  52. ;     - the paging mode field should be specified
  53. ;  The mode set routine will OR in the plane bitfield as it will
  54. ;  change when different color number modes are requested.
  55. ;--------------------------------------------------------------------------
  56.  
  57.     dw    offset mode_set_routine
  58.     dw    offset paging_routine
  59. mode_W  dw    GRD_NEW_DRIVER+GRD_VGA+GRD_1024K+GRD_NO_RW
  60. ;
  61. ; The 'def_xx' fields are filled in by go32 from the corresponding
  62. ; fields of the 'GO32' environment variable
  63. ;
  64. def_tw  dw    80        ; text width
  65. def_th  dw    25        ; text height
  66. def_gw  dw    320        ; graphics width
  67. def_gh  dw    200        ; graphics height
  68. def_nc  dw    16        ; graphics colors
  69.     dw    offset driver_init_routine
  70.     dw    offset text_mode_table
  71.     dw    offset graphics_mode_table
  72.  
  73. ;
  74. ; Biggest text and graphics sizes
  75. ;
  76. Max_TW  equ    80
  77. Max_TH  equ    50
  78. Max_GWn equ    640        ; non interlaced!!!
  79. Max_GHn equ    480
  80. Max_GW  equ    640        ; may be interlaced
  81. Max_GH  equ    480
  82.  
  83.  
  84. ;--------------------------------------------------------------------------
  85. ; TABLE OF SUPPORTED TEXT MODES
  86. ;    - keep sorted by size
  87. ;    - end with an all 0 entry
  88. ;    - BIOS field = 0xff disables it
  89. ;    - fields:
  90. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  91. ;--------------------------------------------------------------------------
  92. text_mode_table        label word
  93.     dw    80,    25,    2,    007h +  00000h
  94.     dw    40,    25,    16,    001h +  00000h
  95.     dw    80,    25,       16,    003h +  00000h
  96.     dw    80,    28,       16,    003h +  00400h  ; 80x25 + reload 14 row font
  97.     dw    80,    50,       16,    003h +  00600h  ; 80x25 + reload 8 row font
  98.     dw    132,    25,       16,    109h +  00000h  ; VESA 109h mode
  99.     dw    132,    28,       16,    109h +  00400h  ; VESA 109h mode (132x25) + reload 14 row font
  100.     dw    132,    44,       16,    10ah +  00000h  ; VESA 10ah mode
  101.     dw    132,    50,       16,    109h +  00600h  ; VESA 109h mode (132x25) + reload 8 row font
  102.     dw    0,    0,        0,    000h +  00000h
  103.  
  104. ;--------------------------------------------------------------------------
  105. ; TABLE OF SUPPORTED GRAPHICS MODES
  106. ;    - keep sorted first by colors then by size
  107. ;    - end with an all 0 entry
  108. ;    - BIOS field = 0xff disables it
  109. ;    - fields:
  110. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  111. ;--------------------------------------------------------------------------
  112. graphics_mode_table    label word
  113.     dw    320,    200,    16,    00dh +  00000h
  114.     dw    640,    200,    16,    00eh +  00000h
  115.     dw    640,    350,    16,    010h +  00000h
  116.     dw    640,    480,      16,    012h +  00000h
  117.     dw    800,    600,    16,    002h +  00100h  ; VESA 102h mode
  118.     dw    320,    200,    256,    013h +  00000h
  119. ;    dw    640,    480,    256,    001h +  00200h  ; VESA S3 201h mode
  120. ;     dw    800,    600,    256,    003h +  00200h  ; VESA S3 203h mode
  121. ;     dw     1024,    768,    256,    005h +  00200h  ; VESA S3 205h mode
  122.        
  123.      dw    640,    480,    256,    001h +  00100h  ; VESA 101h mode
  124.     dw    800,    600,    256,    003h +  00100h  ; VESA 103h mode
  125.     dw     1024,    768,    256,    005h +  00100h  ; VESA 105h mode
  126.         
  127.         dw     640,     480,  0c010h,   011h +  00200h  ; VESA S3 211h mode
  128.         
  129.         dw     640,     480,  0c018h,   012h +  00200h  ; VESA S3 212h mode
  130.         
  131.     dw    0,      0,    0,    000h +  00000h
  132.  
  133. ;--------------------------------------------------------------------------
  134. ; TABLE OF SPECIAL SETUP PROCEDURES
  135. ;  You may need such procedures for:
  136. ;     -- reloading fonts on standard EGA or VGA for
  137. ;     higher resolution text modes
  138. ;     -- enable HiColor mode of some Super VGAs
  139. ;     -- Handle the parameter passing conventions of the VESA BIOS
  140. ;     -- put VGA into 256 color plane mode ("MODE X")
  141. ;     -- etc...
  142. ;  There should be one entry in the table for every non-zero
  143. ;  'setup_procedure_index' in the text and graphics mode tables.
  144. ;  The first entry in the table belongs to index 100h, and so on.
  145. ;  The special setup procedure is invoked via a near call.
  146. ;
  147. ;  Entry: DI=address of the mode record from the text or graphics
  148. ;      table to set up.
  149. ;
  150. ;  Exit:  Adapter configured
  151. ;      BX=driver mode word as it should be returned by the mode set
  152. ;         routine. Typically it involves picking up the mode word
  153. ;         from the header and OR-ing in the appropriate bitplane mode
  154. ;         bitfield. (This is not needed for text modes)
  155. ;      AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  156. ;
  157. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  158. ;--------------------------------------------------------------------------
  159. special_setup_table    label word
  160.     dw    offset  VESA_SVGA_mode_set    ; for 01xxh modes
  161.     dw    offset  VESA_S3_mode_set    ; for 02xxh accelerated S3 modes
  162.         dw      0
  163.     dw    offset  VGA_28_row_mode_set    ; for 28 row text modes
  164.     dw    offset  VGA_28_row_mode_set    ; for 28 row VESA text modes
  165.     dw    offset  VGA_50_row_mode_set    ; for 50 row text modes
  166.     dw    offset  VGA_50_row_mode_set    ; for 50 row VESA text modes
  167.  
  168. ;
  169. ; Routine to set up VGA 50 row mode
  170. ; interface is described above
  171. ;
  172. VGA_50_row_mode_set    proc    near
  173.     mov    ax,WORD PTR [di+6]    ; get base mode number
  174.     and    ah,1            ; clear setup proc index
  175.     je    std_50_mode
  176.     mov    bx,ax
  177.     mov    ax,4f02h
  178.     int    10h
  179.     cmp    ax,004fh        ; VESA error ?
  180.     je    mode_50_done
  181.     mov    ax,3            ; VESA error -- set 80x25 mode
  182. std_50_mode:
  183.     int    10h
  184. mode_50_done:
  185.     xor    bx,bx
  186.     mov    ax,1112h        ; load 8x8 font
  187.     int    10h
  188.     ret
  189. VGA_50_row_mode_set    endp
  190.  
  191. ;
  192. ; Routine to set up VGA 28 row mode
  193. ; interface is described above
  194. ;
  195. VGA_28_row_mode_set      proc     near
  196.     mov    ax,WORD PTR [di+6]    ; get base mode number
  197.     and    ah,1            ; clear setup proc index
  198.     je    std_28_mode
  199.     mov    bx,ax
  200.     mov    ax,4f02h
  201.     int    10h
  202.     cmp    ax,004fh        ; VESA error ?
  203.     je    mode_28_done
  204.     mov    ax,3                  ; VESA error -- set 80x25 mode
  205. std_28_mode:
  206.     int    10h
  207. mode_28_done:
  208.     xor    bx,bx
  209.     mov    ax,1111h        ; load 8x14 font
  210.     int    10h
  211.     ret
  212. VGA_28_row_mode_set     endp
  213.  
  214. ;
  215. ; Routine to set up VESA SVGA modes
  216. ; interface is described above
  217. ;
  218. VESA_SVGA_mode_set    proc      near
  219.     mov    ax,4f02h
  220.     mov    bx,WORD PTR [di+6]
  221.         push    di
  222.     int     10h
  223.         pop     di
  224.     mov     bx,0ffffh             ; error code
  225.     cmp     ax,004fh
  226.     jne       VESA_SVGA_done
  227.  
  228. VESA_SVGA_set_plane:
  229.      mov    bx,GRD_4_PLANES
  230.     cmp       WORD PTR [di+4],16        ; 16 colors ?
  231.     je         VESA_SVGA_done
  232.     mov        bx,GRD_8_PLANES
  233.     cmp        WORD PTR [di+4],256        ; 256 colors ?
  234.     je         VESA_SVGA_done
  235.     mov        bx,GRD_16_PLANES
  236.     cmp        WORD PTR [di+4],32768        ; 32K colors ?
  237.     je         VESA_SVGA_done
  238.     mov        bx,GRD_16_R_PLANES
  239.     cmp        WORD PTR [di+4],0c010h        ; 64K colors ?
  240.     je         VESA_SVGA_done
  241.     mov        bx,GRD_24_PLANES
  242.     cmp        WORD PTR [di+4],0c018h        ; 16M colors ?
  243.     je         VESA_SVGA_done
  244.     mov        bx,GRD_PLANE_MASK        ; something is wrong!!
  245.  
  246. VESA_SVGA_done:
  247.         or      bx,mode_W
  248.     ret
  249. VESA_SVGA_mode_set    endp
  250.  
  251. ; Routine to set up VESA S3 modes
  252. ; interface is described above
  253. ;
  254. VESA_S3_mode_set    proc    near
  255.     mov    ax,4f02h
  256.     mov    bx,WORD PTR [di+6]
  257.         push    di
  258.     int    10h
  259.         pop     di
  260.     mov    bx,0ffffh        ; error code
  261.     cmp     ax,004fh
  262.     jne     VESA_S3_done
  263.         call    VESA_SVGA_set_plane
  264.     xor     bx,(GRD_VGA XOR GRD_S3)
  265. VESA_S3_done:
  266.     ret
  267. VESA_S3_mode_set           endp
  268.  
  269.  
  270. ;--------------------------------------------------------------------------
  271. ; DRIVER INIT ROUTINE
  272. ;  called once after the driver is loaded
  273. ;  may do one or more of the followings:
  274. ;    - check for proper board type
  275. ;    - check amount of RAM on board, and:
  276. ;    -- update word in header to reflect correct amount
  277. ;    -- disable modes in the tables for which there is not enough RAM
  278. ;    - check for special equipment (HiColor DAC, etc...)
  279. ;
  280. ;  Entry: nothing
  281. ;
  282. ;  Exit:  AX=status:
  283. ;       non-zero: OK,
  284. ;       0: something went wrong (e.g. wrong adapter, etc..)
  285. ;      BX,CX,DX may be trashed
  286. ;
  287. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  288. ;--------------------------------------------------------------------------
  289. driver_init_routine    proc    far
  290.     push    di
  291.     push    es
  292.     sub    sp,256
  293.     mov    di,sp
  294.     mov    ax,ss
  295.     mov    es,ax
  296.     mov    ax,4f00h
  297.     int    10h        ; check for VESA BIOS
  298.     cmp    ax,004fh
  299.     jne    init_error
  300.     cmp    BYTE PTR es:[di+0],'V'
  301.     jne    init_error
  302.     cmp    BYTE PTR es:[di+1],'E'
  303.     jne    init_error
  304.     cmp    BYTE PTR es:[di+2],'S'
  305.     jne    init_error
  306.     cmp    BYTE PTR es:[di+3],'A'
  307.     jne    init_error
  308.     mov    ax,1        ; OK, VESA BIOS found
  309.     jmp    init_done
  310. init_error:
  311.     xor    ax,ax
  312. init_done:
  313.     add    sp,256
  314.     pop    es
  315.     pop    di
  316.     ret
  317. driver_init_routine    endp
  318.  
  319.  
  320. ;--------------------------------------------------------------------------
  321. ; MODE SET ROUTINE
  322. ;  sets up a text or graphics mode as close as possible to the one
  323. ;  reguested by the user with regard to number of colors and size.
  324. ;
  325. ;  Entry: AX=mode selection
  326. ;     0 = 80x25 text
  327. ;     1 = default text
  328. ;     2 = text CX cols by DX rows
  329. ;     3 = biggest text
  330. ;     4 = 320x200 graphics
  331. ;     5 = default graphics
  332. ;     6 = graphics CX width by DX height
  333. ;     7 = biggest non-interlaced graphics
  334. ;     8 = biggest graphics
  335. ;     9 = graphics BX colors, CX width by DX height
  336. ;
  337. ;  Exit: BX=driver mode flag
  338. ;     CX=width (in pixels or characters)
  339. ;     DX=height
  340. ;
  341. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  342. ;     YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  343. ;     MUCH TABLE DRIVEN
  344. ;--------------------------------------------------------------------------
  345. mode_set_routine        proc    far
  346.     push    ds
  347.     push    di
  348.     push    si
  349.     mov    si,cs
  350.     mov    ds,si
  351.     cmp    ax,9
  352.     jbe    DoIt
  353.     jmp    Exit
  354. DoIt:    add    ax,ax
  355.     mov    si,ax
  356.     jmp    WORD PTR mode_set_table[si]
  357. mode_set_table  label    word
  358.     dw    offset mode_0
  359.     dw    offset mode_1
  360.     dw    offset mode_2
  361.     dw    offset mode_3
  362.     dw    offset mode_4
  363.     dw    offset mode_5
  364.     dw    offset mode_6
  365.     dw    offset mode_7
  366.     dw    offset mode_8
  367.     dw    offset mode_9
  368. mode_0: mov    si,offset text_mode_table    ; 80x25 text
  369.     mov    bx,def_nc
  370.     mov    cx,80
  371.     mov    dx,25
  372.     jmp    Lookup
  373. mode_1: mov    si,offset text_mode_table    ; default text
  374.     mov    bx,def_nc
  375.     mov    cx,def_tw
  376.     mov    dx,def_th
  377.     jmp    Lookup
  378. mode_2: mov    si,offset text_mode_table    ; CX*DX text
  379.     mov    bx,def_nc
  380.     jmp    Lookup
  381. mode_3: mov    si,offset text_mode_table    ; biggest text
  382.     mov    bx,def_nc
  383.     mov    cx,Max_TW
  384.     mov    dx,Max_TH
  385.     jmp    Lookup
  386. mode_4: mov    si,offset graphics_mode_table    ; 320x200 graphics
  387.     mov    bx,def_nc
  388.     mov    cx,320
  389.     mov    dx,200
  390.     jmp    Lookup
  391. mode_5: mov    si,offset graphics_mode_table    ; default graphics
  392.     mov    bx,def_nc
  393.     mov    cx,def_gw
  394.     mov    dx,def_gh
  395.     jmp    Lookup
  396. mode_6: mov    si,offset graphics_mode_table    ; CX*DX graphics
  397.     mov    bx,def_nc
  398.     jmp    Lookup
  399. mode_7: mov    si,offset graphics_mode_table    ; biggest non-interlaced gr
  400.     mov    bx,def_nc
  401.     mov    cx,Max_GWn
  402.     mov    dx,Max_GHn
  403.     jmp    Lookup
  404. mode_8: mov    si,offset graphics_mode_table    ; biggest graphics
  405.     mov    bx,def_nc
  406.     mov    cx,Max_GW
  407.     mov    dx,Max_GH
  408.     jmp    Lookup
  409. mode_9: mov    si,offset graphics_mode_table    ; CX*DX graphics w/ BX colors
  410. ;
  411. ; At this point:
  412. ;   SI points to the table to search (text or graphics)
  413. ;   BX has colors
  414. ;   CX has width
  415. ;   DX has height
  416. ;
  417. Lookup: xor    ax,ax                ; last color number seen
  418. Find_C: cmp    [si+4],ax            ; last color number == this?
  419.     je     Same_C
  420.     jb    Prev_C                ; end of table -- use last color
  421.     cmp    BYTE PTR [si+6],0ffh        ; valid entry ?
  422.     je    Prev_C                ; not -- use last color
  423.     mov    ax,[si+4]            ; record color number
  424.     mov    di,si                ; start of entries w/ this color
  425.     cmp    ax,bx                ; enough colors ?
  426.     jae    Find_S
  427. Same_C: add    si,8
  428.     jmp    Find_C
  429. Prev_C: or    ax,ax                ; found any color at all?
  430.     je    Exit
  431. ;
  432. ; At this point:
  433. ;   DI points into the table to the first entry with the desired color
  434. ;      number (either it has enough colors or it is the highest color
  435. ;      number supported by the driver). Additionally, at least the
  436. ;      first (= smallest size) entry for this color is valid (has a
  437. ;      valid BIOS number).
  438. ;   AX has the color number adjusted for the driver
  439. ;   CX has width
  440. ;   DX has height
  441. ;
  442. Find_S: cmp    [di+4],ax            ; still the same color #?
  443.     jne    Prev_S
  444.     cmp    BYTE PTR [di+6],0ffh        ; valid entry ?
  445.     je    Prev_S
  446.     cmp    [di],cx
  447.     jb    Next_S
  448.     cmp    [di+2],dx
  449.     jae    GotIt
  450. Next_S: add    di,8
  451.     jmp    Find_S
  452. Prev_S: sub    di,8
  453. ;
  454. ; At this point:
  455. ;   DI points to the table entry we want to set up
  456. ;
  457. GotIt:  mov    ax,[di+6]            ; BIOS mode number
  458.     or     ah,ah                ; special ?
  459.     je    doBIOS
  460.     mov    al,ah
  461.     xor    ah,ah
  462.     dec    ax
  463.     add    ax,ax
  464.     mov    si,ax
  465.     call    WORD PTR special_setup_table[si]
  466.     jmp    RetVal
  467. doBIOS: int    10h
  468.     mov    bx,GRD_1_PLANE
  469.     cmp    WORD PTR [di+4],2        ; 2 colors ?
  470.      je     doFLAG
  471.      mov    bx,GRD_4_PLANES
  472.      cmp    WORD PTR [di+4],16        ; 16 colors ?
  473.      je     doFLAG
  474.      mov    bx,GRD_8_PLANES
  475.     cmp    WORD PTR [di+4],256        ; 256 colors ?
  476.     je     doFLAG
  477.     mov    bx,GRD_16_PLANES
  478.     cmp    WORD PTR [di+4],32768        ; 32K colors ?
  479.     je     doFLAG
  480.     mov    bx,GRD_PLANE_MASK        ; something is wrong!!
  481. doFLAG: or     bx,mode_W
  482. RetVal: mov    cx,[di]
  483.     mov    dx,[di+2]
  484. Exit:    pop    si
  485.     pop    di
  486.     pop    ds
  487.     ret
  488. mode_set_routine    endp
  489.  
  490.  
  491. ;--------------------------------------------------------------------------
  492. ; PAGING ROUTINE
  493. ;
  494. ;  Entry: AH=read page
  495. ;      AL=write page
  496. ;
  497. ;  Exit: VGA configured.
  498. ;     AX,BX,CX,DX,SI,DI may be trashed
  499. ;
  500. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  501. ;     This code must be relocatable and may not reference any data!
  502. ;--------------------------------------------------------------------------
  503.     assume  ds:nothing, es:nothing
  504.  
  505. paging_routine  proc     far
  506.     mov    cl,al        ; save for later
  507.     mov    ax,4838h    ; Unlock S3 extensioon 1
  508.     mov    dx,3d4h
  509.     out    dx,ax
  510.     mov    ax,0a539h    ; Unlock S3 extension 2
  511.     out    dx,ax
  512.     mov    al,31h        ; turn on  paging
  513.     out    dx,al
  514.      inc    dx
  515.     in    al,dx
  516.     or     al,1            ; enable bank register
  517.     out    dx,al
  518.     dec    dx   
  519.     mov    al,35h             ; index CRT Reg. Lock
  520.     out    dx,al
  521.     inc    dx           ; read CRT Reg. Lock
  522.     in    al,dx
  523.     and    al,0f0h        ; update with new bank, bank bits 0..3
  524.         mov     ah,cl
  525.         and     ah,0fh
  526.     or    al,ah
  527.     out    dx,al         ; write CRT Reg. Lock
  528.  
  529.     dec    dx
  530.     mov    al,51h             ; index CRT Reg. Lock
  531.     out    dx,al
  532.     inc    dx           ; read CRT Reg. Lock
  533.     in     al,dx
  534.     and    al,0f3h        ; update with new bank, bank bits 4..5
  535.         mov     ah,cl
  536.         and     ah,030h
  537.         shr     ah,1
  538.         shr     ah,1
  539.     or     al,ah
  540.     out    dx,al         ; write CRT Reg. Lock
  541.         
  542.     mov    ax,0038h    ; Lock S3 extension 1
  543.     dec    dx
  544.     out    dx,ax
  545.     mov    ax,5a39h    ; Lock S3 extension 2
  546.     out    dx,ax
  547.     ret
  548. paging_routine  endp
  549.  
  550. _TEXT    ends
  551.     end
  552.  
  553.